This invention relates generally to electronic circuits. More particularly, this invention relates to integrated electronic circuits and cache memory.
Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing may be used to index and retrieve items in a database or a memory hierarchy because it is usually faster to find the item using the shorter hashed key than to find it using the original value. It may also be used in many encryption algorithms.
The hashing algorithm is called a hash function. The hash function is used to index the original value or key and then used later each time the data associated with the value or key is to be retrieved. A good hash function also should not produce the same hash value from two different inputs. If it does, this is known as a xe2x80x9ccollisionxe2x80x9d. A hash function that offers an extremely low risk of collision may be considered acceptable.
If a collision occurs, another function may be used. This function is commonly called a xe2x80x9ccollision rule.xe2x80x9d The collision rule generates a succession of locations until one is found that is not in use already.
It is desirable, for efficiency reasons, to have as few collisions as possible. To achieve this, the hash function should not be pre-disposed to favor any one particular location or set of locations. In other words, it should spread the potential keys around the table as evenly as possible. This is normally done by making the hash function depend on all parts of the key, computing a large integer from the key, dividing this integer by the table size, and using the remainder as the hash function value. Other commonly used hash functions are the xe2x80x9cfoldingxe2x80x9d method, the xe2x80x9cradix transformationxe2x80x9d method, and xe2x80x9cdigit rearrangementxe2x80x9d method. The type of hash function used is dependent on the application it is designed for.
A hashing function may be designed for indexing memory addresses to cache memory. Designing such a hashing function requires considerable insight into the memory access behavior of the applications that will access the cache. It is not realistically feasible to simulate all possible programs to find an optimal hashing function before the CPU is fabricated. As a result, the hashing function used for indexing memory addresses to cache memory is most likely not optimal for any one application. Having a programmable hashing function would allow the flexibility of index calculation xe2x80x9ctuningxe2x80x9d after the CPU has been designed and implemented. A xe2x80x9ctunedxe2x80x9d hashing function would then allow the cache to operate more efficiently.
This invention allows for many different possible index mappings by programming the hashing function after the CPU has been designed and implemented. By running an application many times, information may be obtained about the application cache memory behavior. With this information, a more optimal hashing function may be derived and implemented for cache indexing. In turn, this results in significant improvement in cache memory performance.
An embodiment of the invention provides a circuit and method for optimizing an index hashing function in a cache memory on a microprocessor. A programmable index hashing function is designed that allows the index hashing function to be programmed after a microprocessor has been fabricated. The index hashing function may be xe2x80x9ctunedxe2x80x9d by running an application on the microprocessor and observing the performance of the cache memory based on the type of index hashing function used. The index hashing function may be programmed by several methods.
Other aspects and advantages of the present invention will become apparent from the following detailed description, taken in conjunction with the accompanying drawing, illustrating by way of example the principles of the invention.